<!DOCTYPE HTML>
<html style="width:100%;height:100%;">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>321 APP_login</title>
    <link rel="stylesheet" type="text/css" href="css/api.css" />
    <link rel="stylesheet" type="text/css" href="css/aui.css" />

</head>

<body style="background-image:url(image/login.png) ;width:100%;height:100%;">
    <div style="padding-top:4rem;padding-bottom: 2rem;">
        <img src="icon/login.png" style="margin:auto;width:5rem;height:5rem;">
    </div>
    <div class="aui-media-list-item-inner" style="margin-top:2rem;">
        <div class="aui-list-item-inner">
            <div class="aui-list-item-text" style="margin-top:0.5rem;">
            </div>
        </div>
        <div class="aui-content aui-margin-b-15" style="background-color:rgb(235,245,234);margin:auto;padding:1rem;border-radius:1rem;">
            <ul class="aui-list aui-form-list" style="border-radius:1rem;">
                <li class="aui-list-item" style="padding-left:0rem;">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="padding-left:1rem;padding-right:0rem;border-style:solid;border-color:#BBB;border-right-width:0.02rem;">
                            学校
                        </div>
                        <div class="aui-list-item-input">
                            <!-- <input type="text" placeholder="用户名" v-model="username" style="padding-left:0.5rem;"> -->
                            <select v-model="currentOrgId" style="padding-left:0.5rem">
                                <option value="" disabled>请选择</option>
                                <option  v-for="item in orgazinations" :key="item.depId" :value="item.depId" v-text="item.depName"></option>
                            </select>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" style="padding-left:0rem;">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="padding-left:1rem;padding-right:0rem;border-style:solid;border-color:#BBB;border-right-width:0.02rem;">
                            账号
                        </div>
                        <div class="aui-list-item-input">
                            <input type="text" placeholder="用户名" v-model="username" style="padding-left:0.5rem;">
                        </div>
                    </div>
                </li>
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="padding-left:1rem;padding-right:0rem;border-style:solid;border-color:#BBB;border-right-width:0.02rem;">
                        密码
                    </div>
                    <div class="aui-list-item-input">
                        <input type="password" placeholder="密码" v-model="password" style="padding-left:0.5rem;">
                    </div>
                </div>
            </ul>
        </div>
    </div>
    <p>
        <div @click="login()" class="aui-btn aui-btn-danger aui-btn-block" @touchstart="zhucestart()" @touchend="zheceend()"
            style="margin:auto;margin-top:1.5rem; width:80%;border-radius:0.5rem;">登录</div>
    </p>
</body>
<script type="text/javascript" src="script/api.js"></script>
<script type="text/javascript" src="script/vue1.0.js"></script>
<script type="text/javascript" src="script/util.js"></script>
<script type="text/javascript">
    var vm;
    apiready = function () {

        vm = new Vue({
            el: "body",
            data: {
                username: "",
                password: "",
                pressed: false,
                orgazinations: null,
                currentOrgId: 0
            },
            watch: {
                currentOrgId: function(val) {
                   setHistoryOrgId(val) 
                }
            },
            methods: {
                zhucestart: function () {
                    this.pressed = true;
                },
                zheceend: function () {
                    this.pressed = false;
                },
                login: function (type, username, password, depId) {
                    if (type != 2) {
                        var me = this;
                        $api.post(serverIp + '/login.do', {
                            values: {
                                depId: me.currentOrgId,
                                username: me.username,
                                password: me.password
                            }
                        }, function (ret) {
                            if (ret) {
                                if (ret.success) {
                                    api.setPrefs({
                                        key: 'user',
                                        value: ret
                                    });
                                    var json = {
                                        username: me.username,
                                        password: me.password,
                                        currentOrgId: me.currentOrgId
                                    };
                                    api.setPrefs({
                                        key: 'usernp',
                                        value: json
                                    });
                                    api.openWin({
                                        name: 'main',
                                        url: './main.html'
                                    });
                                } else {
                                    api.alert({
                                        title: '提示',
                                        msg: ret.message,
                                    });
                                }
                            }
                        }, 'json');
                    } else {
                        $api.post(serverIp + '/login.do', {
                            values: {
                                username: username,
                                password: password,
                                depId: depId
                            }
                        }, function (ret) {
                            if (ret) {
                                if (ret.success) {
                                    api.setPrefs({
                                        key: 'user',
                                        value: ret
                                    });
                                    var json = {
                                        username: username,
                                        password: password,
                                        currentOrgId: depId
                                    };
                                    api.setPrefs({
                                        key: 'usernp',
                                        value: json
                                    });
                                    api.openWin({
                                        name: 'main',
                                        url: './main.html'
                                    });
                                }
                            }
                        }, 'json');
                    }

                }
            },
            created: function () {
                var me = this;
                this.currentOrgId = getHistoryOrgId();
                api.getPrefs({
                    key: 'usernp'
                }, function (ret, err) {
                    if (ret) {
                        if (ret.value != "") {
                            result = JSON.parse(ret.value);
                            me.username = result.username;
                            me.password = result.password;
                            me.login(2, result.username, result.password, result.currentOrgId)
                        }
                    }
                });

            }
        });

        getSchoolInfo();

    }

    function getSchoolInfo() {
        api.showProgress({
            modal: true
        });

        $api.post(serverIp + '/system/listSchoolDepartment.do', function (ret) {
            api.hideProgress();
            console.log(JSON.stringify(ret))
            vm.orgazinations = ret;
            if (ret) {
                setSchoolsInfo(ret)

            } else {
                api.alert({
                    title: '提示',
                    msg: '获取学校信息失败，请检查网络'
                });
            }
        })
    }
</script>

</html>